package com.xiaotu.storage;

import java.util.Date;

import org.springframework.stereotype.Component;

import com.xiaotu.common.util.Constants;
import com.xiaotu.common.util.DataRedisKeyUtils;
import com.xiaotu.common.util.SepratorUtil;
import com.xiaotu.storage.converter.AConverter;
import com.xiaotu.storage.converter.ConverterFactory;
import com.xiaotu.storage.model.CacheDataModel;

import net.sf.json.JSONObject;

/** 
 * 项目名称：Sprider-WebMagic    
 * 类名称：BaiduNewsStorageProcessor    
 * 类描述：    
 * 创建人：张晓 zxaiye1314@163.com    
 * 创建时间：2017年10月14日 上午11:20:33    
 * 修改人：张晓 zxaiye1314@163.com     
 * 修改时间：2017年10月14日 上午11:20:33    
 * 修改备注：       
 * @version   
 */
@Component("BaiduNewsStorageProcessor")
public class BaiduNewsStorageProcessor extends AHSetStorageProcessor{
	
	public static final String[] FIELD_ARR = new String[]{"baiduNewsPlayName", "baiduNewsPlayTitle", "baiduNewsPlayDate",
            "baiduNewsPlayFrom", "baiduNewsPlayContent","timestamp"};
	
	
	
	private static final String[] CONVERT_ARR = new String[]{AConverter.STRING_CONVERT,
            AConverter.STRING_CONVERT, AConverter.STRING_CONVERT, AConverter.STRINGARRAY_CONVERT,
            AConverter.STRINGARRAY_CONVERT,AConverter.TIMESTAMP_CONVERT};

    private static final boolean[] THROW_ARR = new boolean[]{true, true, true, true, true,true};

    @Override
    protected String getRedisKey(Date date)
    {
        return DataRedisKeyUtils.getKey(Constants.DataRedisKey.NetTV_NetPlay_YYYYMMDD, date);
    }

    @Override
    public String process(JSONObject target, CacheDataModel cacheData, Date date)
    {
        this.validateAllNotEmpty(target, FIELD_ARR[0], FIELD_ARR[1], FIELD_ARR[2], FIELD_ARR[6],
                FIELD_ARR[8], FIELD_ARR[10], FIELD_ARR[12]);
        return this.list2CSVLine(ConverterFactory.convert(target, FIELD_ARR, CONVERT_ARR,
                THROW_ARR), SepratorUtil.SEP_PIPE);
    }

    @Override
    public String getDataType()
    {
        return Constants.PageDataType.TV_RECORD;
    }

	@Override
	public String getTaskType() {
		return "BAIDUTV_DATA";
	}
}
